package com.smt.modules.bus.controller;

import java.util.Arrays;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import com.smt.common.base.BaseController;
import com.smt.modules.bus.vo.MemberUserVo;
import com.smt.modules.bus.entity.MemberUserEntity;
import com.smt.modules.bus.service.MemberUserService;
import com.smt.common.utils.PageUtils;
import com.smt.common.utils.R;



/**
 * 成员用户表
 *
 * @author murong
 * @email 981620741@qq.com
 * @date 2018-09-29 15:37:09
 */
@RestController
@RequestMapping("bus/memberuser")
@Api(tags = {"MemberUserController"},description = "成员用户表")
public class MemberUserController extends BaseController{
    @Autowired
    private MemberUserService memberUserService;

    /**
    * 查询成员用户表分页方法
    * @param params
    * @return
    */
    @PostMapping("/list")
    @RequiresPermissions("bus:memberuser:list")
    @ApiOperation(value = "/list",notes = "根据条件查询",response = MemberUserVo.class)
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = memberUserService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{userId}")
    @RequiresPermissions("bus:memberuser:info")
    @ApiOperation(value = "/info/{userId}",notes = "根据表ID查询",response = MemberUserVo.class)
    public R info(@PathVariable("userId") Long userId){
			MemberUserEntity memberUser = memberUserService.selectById(userId);

        return R.ok().put("memberUser", memberUser);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @RequiresPermissions("bus:memberuser:save")
    @ApiOperation(value = "/save",notes = "添加信息保存",response = MemberUserVo.class)
    public R save(@RequestBody MemberUserEntity memberUser){
			memberUserService.insert(memberUser.copyPropertiesTo(new MemberUserEntity()));

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @RequiresPermissions("bus:memberuser:update")
    @ApiOperation(value = "/update",notes = "更新信息保存",response = MemberUserVo.class)
    public R update(@RequestBody MemberUserEntity memberUser){
			memberUserService.updateById(memberUser.copyPropertiesTo(new MemberUserEntity()));

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @RequiresPermissions("bus:memberuser:delete")
    @ApiOperation(value = "/delete",notes = "批量删除",response = MemberUserVo.class)
    public R delete(@RequestBody Long[] userIds){
			memberUserService.deleteBatchIds(Arrays.asList(userIds));

        return R.ok();
    }

}
